package self.zhangkang.chart

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import androidx.fragment.app.viewModels
import self.zhangkang.chart.databinding.FragmentAvgBinding

/**
 * @author：zhangkang19164
 * created on：2025/3/20 14:43
 * description：
 */
class AvgFragment : Fragment() {

    private val mStockDetailsViewModel: StockDetailsViewModel by activityViewModels()

    private val mAvgViewModel: AvgViewModel by viewModels()

    private lateinit var mAvgBinding: FragmentAvgBinding

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        val avgBinding = FragmentAvgBinding.inflate(inflater, container, false)
        mAvgBinding = avgBinding
        return avgBinding.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        mStockDetailsViewModel.shareStock.observe(viewLifecycleOwner) {
            mAvgViewModel.setStock(it)
        }
        mAvgViewModel.avgLiveData.observe(viewLifecycleOwner) {
            mAvgBinding.avgChartView.setKLineData(it)
        }
    }

}